﻿using Device;
using System;
using System.Collections.Generic;
using System.Device.Gpio;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace EMGunSharp
{
    class Launcher
    {
        //sysfs gpio number
        //cat /sys/kernel/debug/gpio

        int CHARGE = 12;
        int LAUNCH = 77;
        GPIO gpioc, gpiol;
        public Launcher()
        {
            if (Environment.GetEnvironmentVariable("PIN_CHARGE") != null) CHARGE = int.Parse(Environment.GetEnvironmentVariable("PIN_CHARGE"));
            if (Environment.GetEnvironmentVariable("PIN_LAUNCH") != null) LAUNCH = int.Parse(Environment.GetEnvironmentVariable("PIN_LAUNCH"));
            //gpio = new GpioController();
            gpioc = new GPIO(CHARGE, GPIO.Direction.Out, GPIO.State.Lo, true);
            gpiol = new GPIO(LAUNCH, GPIO.Direction.Out, GPIO.State.Lo, true);
        }
        public void Charge()
        {
            gpiol.SetPinState(GPIO.State.Lo);
            Thread.Sleep(500);
            gpioc.SetPinState(GPIO.State.Hi);
        }

        public void Launch()
        {
            gpioc.SetPinState(GPIO.State.Lo);
            Thread.Sleep(500);
            gpiol.SetPinState(GPIO.State.Hi);
            Thread.Sleep(1500);
        }
    }
}
